package com.hjqjl.whdemo.db.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.blankj.utilcode.util.LogUtils;
import com.hjqjl.whdemo.app.Config;

public class MyDatabaseHelp extends SQLiteOpenHelper {
    public static Integer VERSION = 1;
//    public static String DBNAME = "WhDemo.db";// 定义数据库名
    private static MyDatabaseHelp instance;


    public MyDatabaseHelp(Context context) {
        super(context, Config.dbName, null, VERSION);
    }

    public static MyDatabaseHelp getInstance(Context context) {

        if (instance == null) {
            instance = new MyDatabaseHelp(context);
        }
        return instance;
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        CreateAnime(sqLiteDatabase);
        LogUtils.v("创建数据库");
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        LogUtils.v("更新数据库版本");
    }

    private void CreateAnime(SQLiteDatabase db) {
        String sqlString = "CREATE TABLE IF NOT EXISTS Anime ("
                + "id INTEGER NOT NULL PRIMARY KEY, "
                + "name varchar(100), "
                + "type varchar(100), "
                + "playDate varchar(100), "
                + "episode INTEGER )";
        db.execSQL(sqlString);
    }
}
